import { Injectable } from '@angular/core'
import { ISearchOption } from '@shared/interfaces/search'
import { I18NService } from '@core'
import { EUserTypeI18n, ELevelI18n } from '@shared/enums'

/** 用户类型权重 */
enum EUserTypeWeight {
  admin = 100,
  genAdmin = 50,
  institution = 40,
  agent = 30,
  merchant = 20,
  store = 10,
}

enum ELevel {
  Institution = 'institution',
  Agent = 'agent',
  Merchant = 'merchant',
  Store = 'store',
}

@Injectable({
  providedIn: 'root',
})
export class LevelService {
  constructor(
    private i18n: I18NService,
  ) {}

  public getLevelOptions(userType: string): ISearchOption[] {
    const weight = EUserTypeWeight[userType]
    return Object.keys(ELevel)
      .filter(key => {
        const value = ELevel[key]
        return EUserTypeWeight[value] <= weight
      })
      .map(key => ({
        label: this.trans(ELevelI18n[key]),
        value: ELevel[key],
      }))
  }

  public trans(str: string): string {
    return this.i18n.fanyi(str)
  }
}
